package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.PagedSelectProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductRequest;
import com.mall.shopping.dto.AllProductResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("shopping")
public class PagedSelectProductController {

    @Reference(interfaceClass = PagedSelectProductService.class,check = false)
    PagedSelectProductService pagedSelectProductService;

    @GetMapping("goods")
    @Anoymous
    public ResponseData goods(Integer page, Integer size, String sort, Integer priceGt, Integer priceLte, Long cid){
        AllProductRequest request = new AllProductRequest(page,size,sort,cid,priceGt,priceLte);
        AllProductResponse response = pagedSelectProductService.queryPageProduct(request);
        if (!response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setErrorMsg(response.getMsg());
        }
        return new ResponseUtil().setData(response);
    }
}
